﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TracNghiemTinHocDaiCuong.ThucThe;
using TracNghiemTinHocDaiCuong.Common;
using TracNghiemTinHocDaiCuong.BIZ;
 

namespace TracNghiemTinHocDaiCuong
{
    public partial class ThemDeThi : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlChuDe.DataSource = ChuDeBIZ.LayDanhSach();
                ddlChuDe.DataBind();
                DateTime dtNgayDangKi = DateTime.Now;
                string ngay = "", thang = "";
                ngay = (dtNgayDangKi.Day < 10) ? ("0" + dtNgayDangKi.Day) : dtNgayDangKi.Day.ToString();
                thang = (dtNgayDangKi.Month < 10) ? ("0" + dtNgayDangKi.Month) : dtNgayDangKi.Month.ToString();
                txtNgayTao.Text = ngay + "/" + thang + "/" + DateTime.Now.Year;
            }
        }

        protected void btnThem_Click(object sender, EventArgs e)
        {
            DeThi DeThi = new DeThi();
            DeThi.TenDT = txtTenDeThi.Text;
            DeThi.MaCD = Methods.ConvertNumber(ddlChuDe.SelectedValue);
            DeThi.DoKho = ddlDoKho.SelectedItem.ToString();
            DeThi.SoCauHoi = Methods.ConvertNumber(txtSoCauHoi.Text);
            DeThi.ThoiGian = Methods.ConvertNumber(txtThoiGian.Text);
            DeThi.NgayTao = Methods.ConvertDateTime(txtNgayTao.Text);
            DeThi.DaThi = false;
            DeThiBIZ.Them(DeThi);
            lblThongBao.Text = "Bạn đã thêm \"" + txtTenDeThi.Text + "\" thành công";
        }

        protected void btnXoaTuKhoa_Click(object sender, EventArgs e)
        {
            txtTenDeThi.Text = "";
            txtSoCauHoi.Text = "";
            txtThoiGian.Text = "";
        }

        protected void btnQuayLai_Click(object sender, EventArgs e)
        {
            Response.Redirect("QuanLyDeThi.aspx");
        }
    }
}